package com.ysd.qxgl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.ysd.qxgl.model.Modules;
import com.ysd.qxgl.service.IModulesService;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/modules")
public class ModulesController {

    @Resource
    private IModulesService modulesService;

    @ApiOperation(value = "查询所有模块",notes = "查询所有模块")
    @GetMapping
    public Map<String ,Object> findAllModules(){
        List<Modules> list=modulesService.findAllModules();
        Map<String ,Object> map=new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("data", list);
        return map;
    }
    @ApiOperation(value = "新增一个模块",notes = "新增一个模块")
    @PostMapping("/addModules")
    public int addModules(@RequestBody Modules modules){
        return modulesService.addModules(modules);
    }
    @ApiOperation(value = "根据模块编号编辑模块信息",notes = "根据模块编号编辑模块信息")
    @PutMapping("/editModule")
    public int editModule(@RequestBody Modules modules){
        return modulesService.editModules(modules);
    }
    @ApiOperation(value = "根据编号删除模块",notes = "根据编号删除模块")
    @DeleteMapping("/delModule/{id}")
    public int delModule(@PathVariable String id){
        return modulesService.delModules(id);
    }

}